package lambdasinaction.chap11.v1;

import java.util.List;
import java.util.function.Supplier;

public class BestPriceFinderMain {

    private static BestPriceFinder bestPriceFinder = new BestPriceFinder();

    public static void main(String[] args) {

        long start = System.nanoTime();

        execute("sequential", () -> bestPriceFinder.findPricesSequential("华为手机"));
        execute("parallel", () -> bestPriceFinder.findPricesParallel("小米手机"));
        execute("composed CompletableFuture", () -> bestPriceFinder.findPricesFuture("魅族手机"));
        execute("combined USD CompletableFuture", () -> bestPriceFinder.findPricesInUSD("三星手机"));
        execute("combined USD CompletableFuture v2", () -> bestPriceFinder.findPricesInUSD2("锤子手机"));
        execute("combined USD CompletableFuture v3", () -> bestPriceFinder.findPricesInUSD3("HTC手机"));


        long duration = (System.nanoTime() - start) / 1_000_000;
        System.out.println("总共用时 " + duration + " msecs");
    }

    private static void execute(String msg, Supplier<List<String>> s) {
        long start = System.nanoTime();
        System.out.println(s.get());
        long duration = (System.nanoTime() - start) / 1_000_000;
        System.out.println(msg + " 做 " + duration + " msecs");
    }
}
